package com.truongnha.clienttn.presentation.adapter;

import java.util.List;

import com.truongnha.clienttn.R;
import com.truongnha.clienttn.business.model.StudentMarkModel;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class StudentMarkByTimeAdapter extends ArrayAdapter<StudentMarkModel> {
	private final List<StudentMarkModel> list;
	private final Activity context;

	public StudentMarkByTimeAdapter(Activity context, List<StudentMarkModel> list) {
		super(context, R.layout.attendance_item, list);
		this.context = context;
		this.list = list;
	}

	static class ViewHolder {
		protected TextView index;
		protected TextView time;
		protected TextView subject ;
		protected TextView type ;
		protected TextView score ;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.student_mark_by_time_item, null);
			final ViewHolder viewHolder = new ViewHolder();

			viewHolder.index = (TextView) view.findViewById(R.id.index);
			viewHolder.time = (TextView) view.findViewById(R.id.time);
			viewHolder.subject = (TextView) view.findViewById(R.id.subject);
			viewHolder.type = (TextView) view.findViewById(R.id.type);
			viewHolder.score = (TextView) view.findViewById(R.id.score);
			view.setTag(viewHolder);
		} else {
			view = convertView;
		}
		ViewHolder holder = (ViewHolder) view.getTag();
		holder.index.setText((position + 1) + "");		
		holder.time.setText(list.get(position).getTimeOtherFormat());
		holder.subject.setText(list.get(position).getSubjectName());
		holder.type.setText(list.get(position).getType());
		holder.score.setText(list.get(position).getScore());
		return view;
	}// end getView
}
